import { reactive } from 'vue';

import { useAsyncState } from '@vueuse/core';

import {Context} from './context';

const states = reactive();

const { state, isReady, isLoading } = useAsyncState(
  axios.get('https://jsonplaceholder.typicode.com/todos/1').then((t) => t.data),
  { id: null },
);

export function makeState(id: string, context: Context) {
  const state = context.block.state || {};
  states[id] = context.parseState(state);
  return states[id];
}
